
namespace KlearTweet.Client.Infrastructure
{
    public static class EventLogger
    {
        public static readonly System.Text.StringBuilder Log = new System.Text.StringBuilder();
        public static event System.EventHandler Updated;

        public static void Verbose(string message)
        {
            var text = System.DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'_'HH'-'mm'-'ss'-'fffffff") + " DEBUG: " + message;
            System.Diagnostics.Debug.WriteLine(text);
            Log.AppendLine(text);
            RaiseUpdated();
        }

        public static void Error(string message, System.Exception ex)
        {
            var text = System.DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'_'HH'-'mm'-'ss'-'fffffff") + " ERROR: " + message;
            if (ex != null)
                text += "\r\n" + ex;
            text += "\r\n";
            System.Diagnostics.Debug.WriteLine(text);
            Log.AppendLine(text);
            RaiseUpdated();
        }

        private static void RaiseUpdated()
        {
            var handler = Updated;
            if (handler != null)
                handler(null, System.EventArgs.Empty);
        }
    }
}